package org.cttic.visualization.visualization.z_service.seven;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.cttic.visualization.visualization.common.module.roadConditionsListData;
import org.cttic.visualization.visualization.util.DateUtil;
import org.cttic.visualization.visualization.util.sevenUtil.QueryEs_roadConditionsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author shkstart
 * @create 2020-06-29 14:58
 * 7.1路况列表
 */
@Service
public class roadConditionsListImpl implements roadConditionsList {

    @Autowired
    private QueryEs_roadConditionsUtil queryUtil;

    @Override
    public String roadConditions(String inputData) {
        cn.hutool.json.JSONObject jsonData = new cn.hutool.json.JSONObject(inputData);
//        JSONObject jsonData = ParseJsonDataUtil.getJsonData(inputData);
        String provinceId = jsonData.getStr("provinceId");
        String roadSectionId = jsonData.getStr("roadSectionId");
        String trafficLevel = jsonData.getStr("trafficLevel");
        String queryType = jsonData.getStr("queryType");
        String queryValue1 = jsonData.getStr("queryValue1");
        int pageNo = jsonData.getInt("pageNo");
        int pageSize = jsonData.getInt("pageSize");
        roadConditionsListData roadConditionsListData = new roadConditionsListData();
        List<roadConditionsListData.ConditionsList> list = new ArrayList<>();

        //todo 时间点查询 查询点上下10分钟信息
        if(queryType.equals("0")){
            String time = DateUtil.TtoTime(queryValue1);
            Long stamp = null;
            try {
                stamp = Long.parseLong(DateUtil.dateToStamp(time));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            String start=DateUtil.StampToDate(stamp-600000);
            String end=DateUtil.StampToDate(stamp+600000);
            roadConditionsListData.setTotalPage(1);
            roadConditionsListData.setTotalCount(20);
            roadConditionsListData.setPageNo(1);
            roadConditionsListData.setPageSize(20);
            queryUtil.queryEs(start,end,provinceId,"1",list);
            roadConditionsListData.setConditionsList(list);
            ObjectMapper mapper = new ObjectMapper();
            try {
                String value = mapper.writeValueAsString(roadConditionsListData);
                System.out.println("######"+value+"######");
                return value;
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
            //todo 时间段查询
        }else if(queryType.equals("1")){

        }




        return null;
    }
}
